﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 影片售票系统
{
    public partial class MainForm : Form
    {
        
        public MainForm()
        {
            InitializeComponent();
      
        }
  

        #region 控件大小随窗体大小等比例缩放
        //private float x;//定义当前窗体的宽度
        //private float y;//定义当前窗体的高度

        //private void setTag(Control cons)
        //{
        //    foreach (Control con in cons.Controls)
        //    {
        //        con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
        //        if (con.Controls.Count > 0)
        //        {
        //            setTag(con);
        //        }
        //    }
        //}
        //private void setControls(float newx, float newy, Control cons)
        //{
        //    //遍历窗体中的控件，重新设置控件的值
        //    foreach (Control con in cons.Controls)
        //    {
        //        //获取控件的Tag属性值，并分割后存储字符串数组
        //        if (con.Tag != null)
        //        {
        //            string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
        //            //根据窗体缩放的比例确定控件的值
        //            con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
        //            con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
        //            con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
        //            con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
        //            Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
        //            con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);

        //            if (con.Controls.Count > 0)
        //            {
        //                setControls(newx, newy, con);
        //            }
        //        }
        //    }
        //}
        #endregion

        private void MainForm_Load(object sender, EventArgs e)
        {

           
           
            this.pictureBox4.Tag = 2;     
            #region  图片对应电影名
            lab_pict1.Parent = pictureBox2;
            lab_pict2.Parent = pictureBox3;
            lab_pict3.Parent = pictureBox4;
            lab_pict4.Parent = pictureBox5;
            lab_pict5.Parent = pictureBox6;
            lab_pict6.Parent = pictureBox7;
            #endregion

            #region 图片显示
            string cv=lab_pict4.Text;       
            string sql = string.Format("select * from T_movie where name='{0}'",cv);
            DataTable table = common.DBHelper.read(sql);
            string zx1 = table.Rows[0]["lujin"].ToString();
            this.pictureBox5.Image = Image.FromFile(zx1);

            string cv1 = lab_pict5.Text.Trim();
            string sql1 = string.Format("select * from T_movie where name='{0}'", cv1);
            DataTable table1 = common.DBHelper.read(sql1);
            string zx2 = table1.Rows[0]["lujin"].ToString();
            this.pictureBox6.Image = Image.FromFile(zx2);

            string cv2 = lab_pict6.Text.Trim();
            string sql2 = string.Format("select * from T_movie where name='{0}'", cv2);
            DataTable table2 = common.DBHelper.read(sql2);
            string zx3 = table2.Rows[0]["lujin"].ToString();
            this.pictureBox7.Image = Image.FromFile(zx3);

            string cv3 = lab_pict2.Text.Trim();
            string sql3 = string.Format("select * from T_movie where name='{0}'", cv3);
            DataTable table3 = common.DBHelper.read(sql3);
            string zx4 = table3.Rows[0]["lujin"].ToString();
            this.pictureBox3.Image = Image.FromFile(zx4);

            string cv4 = lab_pict3.Text.Trim();
            string sql4 = string.Format("select * from T_movie where name='{0}'", cv4);
            DataTable table4 = common.DBHelper.read(sql4);
            string zx5 = table4.Rows[0]["lujin"].ToString();
            this.pictureBox4.Image = Image.FromFile(zx5);

            string cv5 = lab_pict1.Text.Trim();
            string sql5 = string.Format("select * from T_movie where name='{0}'", cv5);
            DataTable table5 = common.DBHelper.read(sql5);
            string zx6 = table5.Rows[0]["lujin"].ToString();
            this.pictureBox2.Image = Image.FromFile(zx6);
            #endregion

            #region 右侧排行榜
            string top1 = lab_Top1.Text.Trim();
            string sql6 = string.Format("select * from T_movie where name='{0}'", top1);
            DataTable table6 = common.DBHelper.read(sql6);
            string zx7 = table6.Rows[0]["lujin"].ToString();
            this.pictureBox10.Image = Image.FromFile(zx7);
            this.lab_pingf1.Text = table6.Rows[0]["pingfen"].ToString();

            string top2 = lab_Top2.Text.Trim();
            string sql7 = string.Format("select * from T_movie where name='{0}'", top2);
            DataTable table7 = common.DBHelper.read(sql6);                   
            this.lab_pingf2.Text = table7.Rows[0]["pingfen"].ToString();

            string top3 = lab_Top3.Text.Trim();
            string sql8 = string.Format("select * from T_movie where name='{0}'", top3);
            DataTable table8 = common.DBHelper.read(sql8);   
            this.lab_pingf3.Text = table8.Rows[0]["pingfen"].ToString();

            string top4 = lab_Top4.Text.Trim();
            string sql9 = string.Format("select * from T_movie where name='{0}'", top4);
            DataTable table9 = common.DBHelper.read(sql9);
            this.lab_pingf4.Text = table9.Rows[0]["pingfen"].ToString();

            string top5 = lab_Top5.Text.Trim();
            string sql10 = string.Format("select * from T_movie where name='{0}'", top5);
            DataTable table10 = common.DBHelper.read(sql10);
            this.lab_pingf5.Text = table10.Rows[0]["pingfen"].ToString();

            #endregion

        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            string name = this.lab_pict1.Text.Trim();
            Yly.Movie movie = new Yly.Movie(name);
            this.Close();
            movie.Show();
          
        }

        private void bangdan_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
         
            Top top = new Top();
            this.Close();
            top.Show();
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {

            string name = this.lab_pict2.Text.Trim();
            Yly.Movie movie = new Yly.Movie(name);
            this.Close();
            movie.Show();
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            string name = this.lab_pict3.Text.Trim();
            Yly.Movie movie = new Yly.Movie(name);
            this.Close();
            movie.Show();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Top top = new Top();
            this.Close();
            top.Show();
        }

        private void lab_Top1_Click(object sender, EventArgs e)
        {
            
            string name = this.lab_Top1.Text.Trim();
            Yly.Movie movie = new Yly.Movie(name);
            this.Close();
            movie.Show();
        }
        #region 右侧排行榜
        private void lab_Top2_Click(object sender, EventArgs e)
        {
            string name = this.lab_Top2.Text.Trim();
            Yly.Movie movie = new Yly.Movie(name);
            this.Close();
            movie.Show();
        }

        private void lab_Top3_Click(object sender, EventArgs e)
        {
            string name = this.lab_Top3.Text.Trim();
            Yly.Movie movie = new Yly.Movie(name);
            this.Close();
            movie.Show();
        }

        private void lab_Top4_Click(object sender, EventArgs e)
        {
            string name = this.lab_Top4.Text.Trim();
            Yly.Movie movie = new Yly.Movie(name);
            this.Close();
            movie.Show();
        }

        private void lab_Top5_Click(object sender, EventArgs e)
        {
            string name = this.lab_Top5.Text.Trim();
            Yly.Movie movie = new Yly.Movie(name);
            this.Close();
            movie.Show();
        }
        #endregion
        #region 设置图片上面的label控件的背景为透明
        private void pictureBox2_Paint(object sender, PaintEventArgs e)
        {
              PictureBox pb = sender as PictureBox;
            foreach (Control C in pb.Controls)
            {
                if (C is Label)
                {
                    Label L = (Label)C;
                    L.Visible = false;
                    e.Graphics.DrawString(L.Text, L.Font, new SolidBrush(L.ForeColor),
                        new RectangleF(L.Left - pb.Left, L.Top - pb.Top, L.Width, L.Height));
                }
            }


        }

        private void pictureBox3_Paint(object sender, PaintEventArgs e)
        {
            PictureBox pb = sender as PictureBox;
            foreach (Control C in pb.Controls)
            {
                if (C is Label)
                {
                    Label L = (Label)C;
                    L.Visible = false;
                    e.Graphics.DrawString(L.Text, L.Font, new SolidBrush(L.ForeColor),
                        new RectangleF(L.Left - pb.Left, L.Top - pb.Top, L.Width, L.Height));
                }
            }
        }

        private void pictureBox4_Paint(object sender, PaintEventArgs e)
        {
            PictureBox pb = sender as PictureBox;
            foreach (Control C in pb.Controls)
            {
                if (C is Label)
                {
                    Label L = (Label)C;
                    L.Visible = false;
                    e.Graphics.DrawString(L.Text, L.Font, new SolidBrush(L.ForeColor),
                        new RectangleF(L.Left - pb.Left, L.Top - pb.Top, L.Width, L.Height));
                }
            }

        }

        private void pictureBox5_Paint(object sender, PaintEventArgs e)
        {
            PictureBox pb = sender as PictureBox;
            foreach (Control C in pb.Controls)
            {
                if (C is Label)
                {
                    Label L = (Label)C;
                    L.Visible = false;
                    e.Graphics.DrawString(L.Text, L.Font, new SolidBrush(L.ForeColor),
                        new RectangleF(L.Left - pb.Left, L.Top - pb.Top, L.Width, L.Height));
                }
            }
        }

        private void pictureBox6_Paint(object sender, PaintEventArgs e)
        {
            PictureBox pb = sender as PictureBox;
            foreach (Control C in pb.Controls)
            {
                if (C is Label)
                {
                    Label L = (Label)C;
                    L.Visible = false;
                    e.Graphics.DrawString(L.Text, L.Font, new SolidBrush(L.ForeColor),
                        new RectangleF(L.Left - pb.Left, L.Top - pb.Top, L.Width, L.Height));
                }
            }
        }

        private void pictureBox7_Paint(object sender, PaintEventArgs e)
        {
            PictureBox pb = sender as PictureBox;
            foreach (Control C in pb.Controls)
            {
                if (C is Label)
                {
                    Label L = (Label)C;
                    L.Visible = false;
                    e.Graphics.DrawString(L.Text, L.Font, new SolidBrush(L.ForeColor),
                        new RectangleF(L.Left - pb.Left, L.Top - pb.Top, L.Width, L.Height));
                }
            }
        }
        #endregion

        private void button1_Click(object sender, EventArgs e)
        {


            if (this.textBox1.Text.Length < 1)
            {
                MessageBox.Show("请输入影片名");
                return;
            }
            string name = this.textBox1.Text.Trim();            
            Yly.MovieSelect select = new Yly.MovieSelect(name);
            select.Show();
       
          
        }

        private void pictureBox8_Click(object sender, EventArgs e)
        {
            string sql = "select * from T_zt";
            DataTable table = common.DBHelper.read(sql);
            int zt = Convert.ToInt16(table.Rows[0]["zhuangtai"]);
            if (zt == 0)
            {
                Zq.Denglu denglu = new Zq.Denglu();
                denglu.Show();
            }
            else
            {
                xiugai xiugai = new xiugai();
                xiugai.Show();
            }
        
        }

        private void lab_pict5_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox5_Click(object sender, EventArgs e)
        {
            string name = this.lab_pict4.Text.Trim();
            Yly.Movie movie = new Yly.Movie(name);
            this.Close();
            movie.Show();
        }

        private void pictureBox6_Click(object sender, EventArgs e)
        {

            string name = this.lab_pict5.Text.Trim();
            Yly.Movie movie = new Yly.Movie(name);
            this.Close();
            movie.Show();
        }

        private void pictureBox7_Click(object sender, EventArgs e)
        {

            string name = this.lab_pict6.Text.Trim();
            
            Yly.Movie movie = new Yly.Movie(name);
            movie.Show();
            this.Hide();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void shouye_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            MainForm mainform = new MainForm();
            this.Close();
            mainform.Show();
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {
            this.textBox1.Text = "请输入相关影视名";
        }

        private void textBox1_Enter(object sender, EventArgs e)
        {
            this.textBox1.Text = "";
        }
       
        private void MainForm_Resize(object sender, EventArgs e)
        {

            
        }

       

        private void panel1_SizeChanged(object sender, EventArgs e)
        {

        }

    }
}
